<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button>按钮</button>
 
  <script>
    // window.onload = function() {  // 等着  页面内容全部加载完
    //   var btn = document.querySelector('button')

    //   console.log(btn)
    // }

    // window.addEventListener('load', function() {
    //   var btn = document.querySelector('button')

    //   console.log(11, btn)
    // })

    window.addEventListener('DOMContentLoaded', function() {
      var btn = document.querySelector('button')

      console.log(11, btn)
    })


  </script>
</body>
</html>